﻿-- =============================================
-- Author:		Jhonatan Christian Belmontes Morales
-- Create date: 09/04/2012
-- Description:	Función para listar doctores
-- =============================================
CREATE FUNCTION fnObtenDoctores
    (
      @pnIdPaciente INT ,
      @pnIdLaboratorio INT 
    )
RETURNS VARCHAR(200)
AS 
    BEGIN

        DECLARE @sDocs VARCHAR(200)
        SELECT  @sDocs = COALESCE(@sDocs + ', ', '') + cd.Nombre
        FROM    dbo.CatDoctor cd
                INNER JOIN dbo.RelPacienteDoctor rpd ON cd.IdDoctor = rpd.IdDoctor
                                                        AND cd.IdLaboratorio = rpd.IdLaboratorio
        WHERE   rpd.IdPaciente = @pnIdPaciente
                AND rpd.IdLaboratorio = @pnIdLaboratorio
        RETURN @sDocs
    END